package cn.wolfcode.service.impl;

import cn.wolfcode.domain.ConsumptionItem;
import cn.wolfcode.domain.ConsumptionItem;
import cn.wolfcode.mapper.ConsumptionItemMapper;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.service.IConsumptionItemService;
import cn.wolfcode.utils.UserContext;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
@Transactional
public class ConsumptionItemServiceImpl implements IConsumptionItemService {
    @Autowired
    private ConsumptionItemMapper consumptionItemMapper ;
    
    @Override
    public void insert(ConsumptionItem consumptionItem) {
        //创建用户
        consumptionItem.setCreateUserId(UserContext.getEmployee().getId());
        //创建时间
        consumptionItem.setCreateTime(new Date());
        consumptionItemMapper.insert(consumptionItem);
    }

    @Override
    public void delete(Long id) {
        consumptionItemMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void update(ConsumptionItem consumptionItem) {
        consumptionItemMapper.updateByPrimaryKey(consumptionItem);
    }

    @Override
    public ConsumptionItem selectById(Long id) {
        ConsumptionItem consumptionItem = consumptionItemMapper.selectByPrimaryKey(id);
        return consumptionItem ;
    }

    @Override
    public List<ConsumptionItem> selectAll() {
        List<ConsumptionItem> consumptionItems = consumptionItemMapper.selectAll();
        return consumptionItems ;
    }

    @Override
    public PageInfo<ConsumptionItem> query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<ConsumptionItem> consumptionItems = consumptionItemMapper.queryAll(qo);
        return new PageInfo<>(consumptionItems);
    }

    @Override
    public List<ConsumptionItem> selectByCno(String cno) {
        List<ConsumptionItem> consumptionItems = consumptionItemMapper.selectByCno(cno);
        return consumptionItems;
    }
}
